<template>
  <el-form class="addmoban" ref="form" :model="tbuser" label-width="80px">
    <el-form-item>
      <h1 style="text-align: center">用户添加</h1>
    </el-form-item>
    <el-row>
      <el-col :span="12">
        <el-form-item label="*用户名">
          <el-input style="width: 163px" v-model="tbuser.name"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="部门">
          <el-select style="width: 163px" v-model="tbuser.region" placeholder="请选择部门">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="*昵称">
          <el-input style="width: 163px" v-model="tbuser.name"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="性别" prop="sex" >
          <el-radio v-model="radio" label="1">美女</el-radio>
          <el-radio v-model="radio" label="0">帅哥</el-radio>
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item label="*邮箱">
      <el-input v-model="tbuser.name"></el-input>
    </el-form-item>
    <el-form-item label="*联系方式">
      <el-input v-model="tbuser.name"></el-input>
    </el-form-item>
    <el-form-item label="生日">
      <div class="block">
        <el-date-picker
          v-model="dateValue"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </div>
    </el-form-item>
    <el-form-item>
      <el-upload
        class="avatar-uploader"
        action="http://localhost:8003/aliOss/uploadFileImage"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :before-upload="beforeAvatarUpload">
        <img v-if="imageUrl" :src="imageUrl" class="avatar">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
    </el-form-item>
    <el-form-item style="text-align: center">
      <el-button type="primary" @click="onSubmit">立即创建</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  export default {
    data() {
      return {
        imageUrl:null,
        dateValue:2020-9-9,
        radio: 0,
        tbuser: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        }
      }
    },
    methods: {
      onSubmit() {
        console.log('submit!');
      },
      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      }
    }
  }

</script>
<style>
  .addmoban {
    margin: auto;
    width: 45%;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>

